# Maintainer: <matheus-catarino@hotmail.com>

_realname=nana
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.4
pkgrel=3
pkgdesc="An opensource cross-platform GUI library written in modern C++11 for static linking (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/cnjinhao/${_realname}"
license=("spdx:BSL-1.0")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libpng" "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-ninja")
source=("${_realname}-v${pkgver}.tar.gz"::"https://github.com/cnjinhao/${_realname}/archive/v${pkgver}.tar.gz"
        010-thread.patch
        011-march.patch)
sha256sums=('56f7b1ed006c750fccf8ef15ab1e83f96751f2dfdcb68d93e5f712a6c9b58bcb'
            '91d37c90ff54bfb9d97f3f2eddb12a04d7093af65fe0ba93ddeb1e04583f5659'
            '38616fc7ffa107a226716e983d1fcaafcd222f51b2129425e4dba9a067ad561d')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/010-thread.patch
  patch -p1 -i ${srcdir}/011-march.patch
}

build() {
  cd ${srcdir}/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_CXX_STANDARD=17 \
    -DNANA_CMAKE_ENABLE_JPEG=YES \
    -DNANA_CMAKE_ENABLE_PNG=YES \
    -DNANA_CMAKE_INSTALL=YES \
    -DNANA_CMAKE_NANA_FILESYSTEM_FORCE=NO \
    -DNANA_CMAKE_STD_FILESYSTEM_FORCE=YES \
    ../${_realname}-${pkgver}
    
  cmake --build .
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" cmake --install .
}
